package com.flink.datastreamapi.function;

import com.flink.datastreamapi.bean.WaterSensor;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

//使用Lambda表达式简化
public class FunctionUDFDemo4 {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> stream = env.fromElements(

                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_2", 2L, 2),
                new WaterSensor("sensor_3", 3L, 3)
        );

        DataStream<WaterSensor> filter = stream.filter( value -> value.id.equals("sensor_1"));

        //其实是对匿名内部类的简化
//        DataStream<WaterSensor> filter = stream.filter(new FilterFunction<WaterSensor>() {
//            @Override
//            public boolean filter(WaterSensor value) throws Exception {
//                return value.id.equals("sensor_1");
//            }
//        });
        filter.print();
        env.execute();
    }




}
